<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of welcome
 *
 * @author Obi
 */
class Admin_sekuritas extends MY_Controller {

    function __construct() {
        parent::__construct();
        
        $cek_admin = $this->session->userdata('cek_admin');
        if (!$cek_admin)
            redirect("admin");

        $this->msekuritas = new M_sekuritas();
    }

    function index() {

        $data['title'] = 'Data Securities';
		
        $data['list'] = $this->msekuritas->select_data();

        $data['isi'] = 'isi';
        $this->load->view('template_admin', $data);
    }

    function tambah() {

        $data['title'] = 'Add Securities';

        $data['id'] = "";
        $data['symbol'] = "";
        $data['name'] = "";
        $data['address'] = "";
        $data['contact'] = "";
        $data['phone'] = "";
        $data['mobile'] = "";
        $data['fax'] = "";
        $data['email'] = "";
        $data['bank'] = "";
        $data['nameaccount'] = "";
        $data['$accountnumber'] = "";
        $data['buyfee'] = "";
        $data['sellfee'] = "";
        $data['selltax'] = "";

        $data['isi'] = 'form';
        $this->load->view('template_admin', $data);
    }

    function edit($id = NULL) {

        $data['title'] = 'Edit Securuties';

        $dt = $this->msekuritas->where("id = '$id'")->get();
		
		$data['id'] = $dt->id;
        $data['symbol'] =  $dt->security_code;
        $data['name'] = $dt->security_name;
        $data['address'] = $dt->address;
        $data['contact'] = $dt->contact;
        $data['phone'] = $dt->phone;
        $data['mobile'] = $dt->mobile;
        $data['fax'] = $dt->fax;
        $data['email'] = $dt->email;
        $data['bank'] = $dt->bank_account;
        $data['nameaccount'] = $dt->name_of_account;
        $data['accountnumber'] = $dt->account_number;
        $data['buyfee'] = $dt->buy_fee;
        $data['sellfee'] = $dt->sell_fee;
        $data['selltax'] = $dt->sell_tax;
		
        $data['isi'] = 'form';
        $this->load->view('template_admin', $data);
    }

    function delete($id) {
        $this->msekuritas->delete($id);
        redirect("admin_sekuritas");
    }

    function simpan() {
        $id = $this->input->post('id');

        $data = array(
            'security_code' => $this->input->post('symbol'),
            'security_name' => $this->input->post('name'),
            'address' => $this->input->post('address'),
            'contact' => $this->input->post('contact'),
            'phone' => $this->input->post('phone'),
            'mobile' => $this->input->post('mobile'),
            'fax' => $this->input->post('fax'),
            'email' => $this->input->post('email'),
            'bank_account' => $this->input->post('bank'),
            'name_of_account' => $this->input->post('nameaccount'),
            'account_number' => $this->input->post('accountnumber'),
            'buy_fee' => $this->input->post('buyfee'),
            'sell_fee' => $this->input->post('sellfee'),
            'sell_tax' => $this->input->post('selltax')
        );

        if ($id == "") {
            $this->msekuritas->insert($data);
			$this->msekuritas->insertLocstock($this->input->post('symbol'));
        } else {
            $this->msekuritas->update($data, $id);
        }

        redirect("admin_sekuritas");
    }

}

?>
